home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / WFC010.ZIP / SRC / CSERVER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  7.3 KB  |  376 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like as long as you don't try to sell it.
  10. **
  11. ** Any attempt to sell WFC in source code form must have the permission
  12. ** of the original author. You can produce commercial executables with
  13. ** WFC but you can't sell WFC.
  14. **
  15. ** Copyright, 1995, Samuel R. Blackburn
  16. **
  17. ** $Workfile: $
  18. ** $Revision: $
  19. ** $Modtime: $
  20. */
  21.  
  22. #if defined( _DEBUG )
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. IMPLEMENT_SERIAL( CServer, CNetwork, 1 )
  28.  
  29. #if defined( _DEBUG )
  30. #define new DEBUG_NEW
  31. #endif
  32.  
  33. CServer::CServer()
  34. {
  35.    m_Initialize();
  36. }
  37.  
  38. CServer::CServer( LPCTSTR machine_name )
  39. {
  40.    Open( machine_name );
  41. }
  42.  
  43. CServer::~CServer()
  44. {
  45.    Close();
  46. }
  47.  
  48. void CServer::Close( void )
  49. {
  50.    CNetwork::Close();
  51.    m_Initialize();
  52. }
  53.  
  54. void CServer::GetComment( CString& comment )
  55. {
  56.    comment.Empty();
  57.  
  58.    /*
  59.    ** Test m_ServerName of emptiness because a lot of comments are blank
  60.    */
  61.  
  62.    if ( m_Retrieved102 != TRUE )
  63.    {
  64.       m_Get_102_Data();
  65.    }
  66.  
  67.    comment = m_Comment;
  68. }
  69.  
  70. void CServer::GetDomain( CString& name )
  71. {
  72.    name.Empty();
  73.  
  74.    /*
  75.    ** Yes, domain is a member of the 503 structure, but that call doesn't work.
  76.    ** We've got to use 599. Although for numsessions we have to use 503, go figure
  77.    */
  78.  
  79.    if ( m_Retrieved599 != TRUE )
  80.    {
  81.       m_Get_599_Data();
  82.    }
  83.  
  84.    name = m_Domain;
  85. }
  86.  
  87. DWORD CServer::GetMajorVersion( void )
  88. {
  89.    if ( m_Retrieved102 != TRUE )
  90.    {
  91.       m_Get_102_Data();
  92.    }
  93.  
  94.    return( m_MajorVersion );
  95. }
  96.  
  97. DWORD CServer::GetMinorVersion( void )
  98. {
  99.    if ( m_Retrieved102 != TRUE )
  100.    {
  101.       m_Get_102_Data();
  102.    }
  103.  
  104.    return( m_MinorVersion );
  105. }
  106.  
  107. DWORD CServer::GetNumberOfOpens( void )
  108. {
  109.    if ( m_Retrieved503 != TRUE )
  110.    {
  111.       m_Get_503_Data();
  112.    }
  113.  
  114.    return( m_NumberOfOpens );
  115. }
  116.  
  117. DWORD CServer::GetNumberOfUsers( void )
  118. {
  119.    if ( m_Retrieved503 != TRUE )
  120.    {
  121.       m_Get_503_Data();
  122.    }
  123.  
  124.    return( m_NumberOfUsers );
  125. }
  126.  
  127. void CServer::GetName( CString& name )
  128. {
  129.    name.Empty();
  130.  
  131.    if ( m_Retrieved102 != TRUE )
  132.    {
  133.       m_Get_102_Data();
  134.    }
  135.  
  136.    name = m_MachineName;
  137. }
  138.  
  139. DWORD CServer::GetPlatform( void )
  140. {
  141.    if ( m_Retrieved102 != TRUE )
  142.    {
  143.       m_Get_102_Data();
  144.    }
  145.  
  146.    return( m_Platform );
  147. }
  148.  
  149. void CServer::GetPlatformName( CString& name )
  150. {
  151.    name.Empty();
  152.  
  153.    /*
  154.    ** Test m_ServerName of emptiness because a lot of comments are blank
  155.    */
  156.  
  157.    if ( m_Retrieved102 != TRUE )
  158.    {
  159.       m_Get_102_Data();
  160.    }
  161.  
  162.    switch( m_Platform )
  163.    {
  164.       case SV_PLATFORM_ID_OS2:
  165.  
  166.          name = "OS/2";
  167.          return;
  168.  
  169.       case SV_PLATFORM_ID_NT:
  170.  
  171.          name = "NT";
  172.          return;
  173.  
  174.       default:
  175.  
  176.          CString temp_name( "" );
  177.  
  178.          temp_name.Format( "Unknown Type %d", m_Platform );
  179.          name = temp_name;
  180.          return;
  181.    }
  182. }
  183.  
  184. void CServer::GetPlatformNameAndVersion( CString& name )
  185. {
  186.    name.Empty();
  187.  
  188.    CString temp_name;
  189.  
  190.    GetPlatformName( temp_name );
  191.  
  192.    name.Format( "%s %d.%d", (LPCTSTR) temp_name, m_MajorVersion, m_MinorVersion );
  193. }
  194.  
  195. DWORD CServer::GetType( void )
  196. {
  197.    if ( m_Retrieved102 != TRUE )
  198.    {
  199.       m_Get_102_Data();
  200.    }
  201.  
  202.    return( m_Type );
  203. }
  204.  
  205. void CServer::GetUserPath( CString& path )
  206. {
  207.    path.Empty();
  208.  
  209.    if ( m_Retrieved102 != TRUE )
  210.    {
  211.       m_Get_102_Data();
  212.    }
  213.  
  214.    path = m_UserPath;
  215. }
  216.  
  217. DWORD CServer::GetUsers( void )
  218. {
  219.    if ( m_Retrieved102 != TRUE )
  220.    {
  221.       m_Get_102_Data();
  222.    }
  223.  
  224.    return( m_Users );
  225. }
  226.  
  227. void CServer::m_Get_102_Data( void )
  228. {
  229.    LPBYTE buffer = (LPBYTE) NULL;
  230.  
  231.    /*
  232.    ** One of the children got loose in the header files again...
  233.    **
  234.    ** Also, we can't get 101 information because it doesn't work if you supply
  235.    ** a machine name... Go Figure...
  236.    */
  237.  
  238.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 102, &buffer );
  239.  
  240.    if ( buffer != NULL )
  241.    {
  242.       SERVER_INFO_102 *information_p = (SERVER_INFO_102 *) buffer;
  243.  
  244. #if ! defined( UNICODE )
  245.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_name,     information_p->sv102_name     );
  246.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_comment,  information_p->sv102_comment  );
  247.       ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv102_userpath, information_p->sv102_userpath );
  248. #endif
  249.  
  250.       /*
  251.       ** Now store the info we want...
  252.       */
  253.  
  254.       m_MachineName  = information_p->sv102_name;
  255.       m_UserPath     = information_p->sv102_userpath;
  256.       m_Users        = information_p->sv102_users;
  257.       m_Comment      = information_p->sv102_comment;
  258.       m_Platform     = information_p->sv102_platform_id;
  259.       m_MajorVersion = information_p->sv102_version_major;
  260.       m_MinorVersion = information_p->sv102_version_minor;
  261.       m_Type         = information_p->sv102_type;
  262.       m_Retrieved102 = TRUE;
  263.    }
  264. }
  265.  
  266. void CServer::m_Get_503_Data( void )
  267. {
  268.    LPBYTE buffer = (LPBYTE) NULL;
  269.  
  270.    /*
  271.    ** One of the children got loose in the header files again...
  272.    */
  273.  
  274.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 503, &buffer );
  275.  
  276.    if ( buffer != NULL )
  277.    {
  278.       SERVER_INFO_503 *information_p = (SERVER_INFO_503 *) buffer;
  279.  
  280.       /*
  281.       ** Now store the info we want...
  282.       */
  283.  
  284.       m_NumberOfUsers = information_p->sv503_sessusers;
  285.       m_NumberOfOpens = information_p->sv503_sessopens;
  286.       m_Retrieved503  = TRUE;
  287.    }
  288. }
  289.  
  290. void CServer::m_Get_599_Data( void )
  291. {
  292.    LPBYTE buffer = (LPBYTE) NULL;
  293.  
  294.    /*
  295.    ** One of the children got loose in the header files again...
  296.    */
  297.  
  298.    ::NetServerGetInfo( (LPTSTR) m_WideMachineName, 599, &buffer );
  299.  
  300.    if ( buffer != NULL )
  301.    {
  302.       SERVER_INFO_599 *information_p = (SERVER_INFO_599 *) buffer;
  303.  
  304. #if ! defined( UNICODE )
  305.  
  306.       if ( information_p->sv599_domain != NULL )
  307.       {
  308.          ::UNICODE_to_ASCII( (LPCWSTR) information_p->sv599_domain, information_p->sv599_domain );
  309.       }
  310.       else
  311.       {
  312.          information_p->sv599_domain = " ";
  313.       }
  314.  
  315. #endif
  316.  
  317.       /*
  318.       ** Now store the info we want...
  319.       */
  320.  
  321.       m_Domain       = information_p->sv599_domain;
  322.       m_Retrieved599 = TRUE;
  323.    }
  324. }
  325.  
  326. void CServer::m_Initialize( void )
  327. {
  328.    m_Comment.Empty();
  329.    m_UserPath.Empty();
  330.  
  331.    m_Retrieved102 = FALSE;
  332.    m_Retrieved503 = FALSE;
  333.    m_Retrieved599 = FALSE;
  334.  
  335.    m_MajorVersion  = 0;
  336.    m_MinorVersion  = 0;
  337.    m_NumberOfUsers = 0;
  338.    m_NumberOfOpens = 0;
  339.    m_Platform      = 0;
  340.    m_Type          = 0;
  341.    m_Users         = 0;
  342. }
  343.  
  344. void CServer::Serialize( CArchive& archive )
  345. {
  346.    CNetwork::Serialize( archive );
  347.  
  348.    if ( archive.IsStoring() )
  349.    {
  350.       archive << m_Comment;
  351.       archive << m_UserPath;
  352.       archive << m_Domain;
  353.       archive << m_MajorVersion;
  354.       archive << m_MinorVersion;
  355.       archive << m_NumberOfOpens;
  356.       archive << m_NumberOfUsers;
  357.       archive << m_Platform;
  358.       archive << m_Type;
  359.       archive << m_Users;
  360.    }
  361.    else
  362.    {
  363.       archive >> m_Comment;
  364.       archive >> m_UserPath;
  365.       archive >> m_Domain;
  366.       archive >> m_MajorVersion;
  367.       archive >> m_MinorVersion;
  368.       archive >> m_NumberOfOpens;
  369.       archive >> m_NumberOfUsers;
  370.       archive >> m_Platform;
  371.       archive >> m_Type;
  372.       archive >> m_Users;
  373.    }
  374. }
  375.  
  376.